/* 
 * String FIFO Buffer Utility
 * Joel PC Filho
 * 01/10/2013
 */

#ifndef BUFFER_H
#define	BUFFER_H

    typedef struct _buffer buffer;
    

    /**
     * Reset parameters for a buffer 'buf'.<br>
     * Set the buffer container bufArray with length bufSize.
     *
     * Example code:<br/>
     * <code>
     * char array[100];<br/>
     * buffer buf;<br/>
     * buildBuffer(&buf, array, 100);<br/>
     * </code>
     */
    void buildBuffer(buffer *buf, BYTE *bufArray, int bufSize);

    /**
     * Insert the given string in the buffer 'buf'.
     *
     * Example code: <br/>
     * <code>
     * char array[100];<br/>
     * buffer buf;<br/>
     * buildBuffer(&buf, array, 100);<br/>
     * char string[10] = "Hello World!";<br/>
     * bufferize(&buf, string);
     * </code>
     *
     * @param buf &nbsp; Initialized Buffer
     * @param string &nbsp; String ending with "&#92;0"
     */
    void bufferize(buffer *buf, const char *string);

    /**
     * Defines if the buffer buf is full.
     * @return <p>1, if buffer is full<br/>0, otherwhise</p>
     */
    BYTE fullBuffer(buffer *buf);

    /**
     * Defines if the buffer buf is empty.
     * @return <p>1, if buffer is empty<br/>0, otherwhise</p>
     */
    BYTE emptyBuffer(buffer *buf);
    
    BYTE nextBufferChar(buffer *buf);
    void bufferizeChar(buffer *buf, char c);
    void resetBuffer(buffer *buf);

    struct _buffer{
        BYTE *outputBuffer; // Pointer to output buffer array
        int bufferStart;    // Buffer Start Index
        int bufferEnd;      // Buffer End Index
        int bufferSize;     // Buffer Length
        char lastModified;  // Buffer Status
    };

#endif